package com.heba.popupwindow;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.heba.greenmulu.R;
import com.heba.popupwindow.callback.SortClickListener;


/**
 * 排序彈出窗口
 * Created by shenghao on 2019/1/9.
 */
public class SortPopupWindow extends BasePopupWindow implements View.OnClickListener {

    private TextView tv_new, tv_collect, tv_review, tv_brand, tv_product;

    private SortClickListener sortClickListener;

    public SortPopupWindow(Context context) {
        super(LayoutInflater.from(context).inflate(
                R.layout.popup_sort, null));
//        setAnimationStyle(R.style.Popup_Animation_Translate);
    }

    public SortPopupWindow(Context context, int width, int height) {
        super(context, LayoutInflater.from(context).inflate(
                R.layout.popup_sort, null), width, height);
//        setAnimationStyle(R.style.Popup_Animation_Translate);
    }

    @Override
    public void initViews() {
        tv_new = (TextView) findViewById(R.id.tv_new);
        tv_collect = (TextView) findViewById(R.id.tv_collect);
        tv_review = (TextView) findViewById(R.id.tv_review);
        tv_brand = (TextView) findViewById(R.id.tv_brand);
        tv_product = (TextView) findViewById(R.id.tv_product);
    }

    @Override
    public void initEvents() {
        tv_new.setOnClickListener(this);
        tv_collect.setOnClickListener(this);
        tv_review.setOnClickListener(this);
        tv_brand.setOnClickListener(this);
        tv_product.setOnClickListener(this);

        tv_new.setTag(1);
        tv_collect.setTag(2);
        tv_review.setTag(3);
        tv_brand.setTag(4);
        tv_product.setTag(5);
    }

    @Override
    public void init() {
    }

    @Override
    public void onClick(View v) {
        int tag = (int) v.getTag();
        if (sortClickListener != null) {
            sortClickListener.onSortClick(tag);
        }
        dismiss();
    }

    /**
     * @param sortClickListener
     */
    public void setOnSortClickListener(SortClickListener sortClickListener) {
        this.sortClickListener = sortClickListener;
    }

}
